package net.elive.common.p2pnet.message;

import java.net.DatagramPacket;

import net.elive.common.p2pnet.AbstractMessage;
import net.elive.tools.ByteIntSwitch;
import net.elive.tools.ByteShortSwitch;
import net.elive.tools.MessageType;

/**
 * 注册后返回数据包
 * @author jincool.cao@gmail.com
 *
 */
public class RegisterMessageBack extends AbstractMessage{

	private short sType = MessageType.STYPE_REGMESSAGE_BACK;
	private int sessionId = 0;
	byte[] dpData = new byte[8];
	
	public RegisterMessageBack(){
		ByteShortSwitch.toByteArray(version, dpData, 0);		//添加版本号
		ByteShortSwitch.toByteArray(sType, dpData, 2);			//消息类型
		ByteIntSwitch.toByteArray(sessionId, dpData, 4);		//添加session
		dp = new DatagramPacket(dpData,dpData.length);
	}
	public RegisterMessageBack(DatagramPacket dp){
		this.dp = dp;
		dpData = dp.getData();
		version = ByteShortSwitch.toShort(dpData, 0);
		sType = ByteShortSwitch.toShort(dpData, 2);
		sessionId = ByteIntSwitch.toInt(dpData, 4);
	}
	/**
	 * 设置session
	 * @param sessionId
	 */
	public void setSessionId(int sessionId){
		this.sessionId =sessionId;
		ByteIntSwitch.toByteArray(sessionId, dpData, 4);		//添加session
	}
	/**
	 * 获取sessionId
	 * @return
	 */
	public int getSessionId(){
		return sessionId;
	}
	
	
}
